package logic

import (
	"context"
	"teacher1/studentrpc/studentrpc"

	"teacher1/api/internal/svc"
	"teacher1/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StudentAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStudentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StudentAddLogic {
	return &StudentAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StudentAddLogic) StudentAdd(req *types.StudentAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.StudentRpc.StudentAdd(l.ctx, &studentrpc.StudentAddRequest{
		Number:    req.Number,
		IdCard:    req.IdCard,
		RealName:  req.RealName,
		Mobile:    req.Mobile,
		Job:       req.Job,
		HeadImg:   req.HeadImg,
		TeaCherId: req.TeaCherId,
	})
	if err != nil {
		return &types.Response{
			Msg:  "添加失败" + err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "添加成功",
		Code: 200,
		Data: add,
	}, nil
}
